package com.yswy.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yswy.app.dto.domianVo.ManagementMenuVo;
import com.yswy.app.service.AppUserService;
import com.yswy.app.service.ManagementMenuService;
import com.yswy.app.service.PackageManageService;
import com.yswy.app.service.SysConfigService;
import com.yswy.common.utils.DateUtils;
import com.yswy.domain.entity.AppUser;
import com.yswy.domain.entity.ManagementMenu;
import com.yswy.domain.entity.PackageManage;
import com.yswy.domain.mapper.ManagementMenuMapper;
import com.yswy.domain.mapper.PackageBingMenuMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Slf4j
@Service
public class ManagementMenuServiceImpl extends ServiceImpl<ManagementMenuMapper, ManagementMenu>
        implements ManagementMenuService {
    @Autowired
    private PackageBingMenuMapper packageBingMenuMapper ;
    @Autowired
    private PackageManageService  packageManageService ;
    @Autowired
    private AppUserService appUserService;
    @Autowired
    private SysConfigService configService;
    @Override
    public List<ManagementMenuVo> getAll(Long userId) {
        AppUser appUser = appUserService.getById(userId);
        Boolean isShow = false ;


//        PackageManage packageManage = packageManageService.gePackageManageByChannle(channle);
        List<ManagementMenu> managementMenus = packageBingMenuMapper.getByPackageId(
                appUser.getPackageManageId(),isShow);
        List<ManagementMenuVo> managementMenuVos = new ArrayList<>();

        for (ManagementMenu m:managementMenus
             ) {
//            if (m.getGoToPage().equals("R.id.midnight")){
//                String openTime = configService.selectConfigByKey("sys.theater.openTime");
//                String[] openTimes = openTime.split("-");
//                SimpleDateFormat simpleDateFormat = DateUtils.getSimpleDateFormat(DateUtils.HH_MM_SS);
//                try {
//                    Date date =simpleDateFormat.parse(openTimes[0]);
//                    Date date1 =simpleDateFormat.parse(openTimes[1] );
//                    Boolean belong ;
//                    if (date.after(date1) ){
//                        belong = DateUtils.belongCalendar(openTimes[0], "23:59:59" , DateUtils.HH_MM_SS) ||
//                                DateUtils.belongCalendar("00:00:00",openTimes[1]   , DateUtils.HH_MM_SS) ;
//                    }else {
//                        belong = DateUtils.belongCalendar(openTimes[0], openTimes[1]  , DateUtils.HH_MM_SS);
//                    }
//                    if (!belong){
//                        continue;
//                    }
//                }catch (Exception e){
//                    e.printStackTrace();
//                }
//
//            }
            managementMenuVos.add(new ManagementMenuVo(m));
        }
        return managementMenuVos;
    }

    public static void main(String[] args) throws ParseException {

        String openTime = "09:00:00-05:00:00";
        String newTime = "10:12:00" ;
        String[] openTimes = openTime.split("-");
        SimpleDateFormat simpleDateFormat = DateUtils.getSimpleDateFormat(DateUtils.HH_MM_SS);
        Date date =simpleDateFormat.parse(openTimes[0]);
        Date date1 =simpleDateFormat.parse(openTimes[1] );
        System.out.println(date.after(date1));
        Boolean belong ;
        if (date.after(date1) ){
            belong = DateUtils.belongCalendar(openTimes[0], "23:59:59" ,newTime , DateUtils.HH_MM_SS) ||
                    DateUtils.belongCalendar("00:00:00",openTimes[1] ,newTime  , DateUtils.HH_MM_SS) ;
        }else {
            belong = DateUtils.belongCalendar(openTimes[0], openTimes[1]  , DateUtils.HH_MM_SS);
        }

        System.out.println(belong);
    }


}
